package negocio;

import java.util.List;


import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.Query;


import modelo.Persona;

@Stateless
public class PersonaDAO {
	
	@Inject
	private EntityManager em;
	
	public void insert(Persona p){
		
		
		em.persist(p);
		
		
	}
	
	
	public void update(Persona p){
		
		em.merge(p);
		
	}
	
	
	public void remove(Persona p){
		em.remove(p);
	}	
	
	public Persona read(String cedula){
		Persona p = em.find(Persona.class, cedula);
		return p;
	}
	
	public List<Persona> getPersonas(int  edadMinima){
		
		String sql = "SELECT p From Persona p WHERE p.edad  > :edadminima";
		
		Query q =  em.createQuery(sql, Persona.class);
		q.setParameter("edadminima", edadMinima);
		
		List<Persona> lst = q.getResultList();
		
		return lst;
	}
	
	
	public List<Persona> getPersonasNQ(int  edadMinima){
		
		String sql = "SELECT * from tbl_persona p WHERE p.edad  > :edadminima";
		
		Query q =  em.createNamedQuery(sql, Persona.class);
		q.setParameter("edadminima", edadMinima);
		
		List<Persona> lst = q.getResultList();
		
		return null;
	}



}
